Using The JSON Decoder Plugin
Procedure
- Start Spoon by navigating to your Kettle directory and running spoon.bat. Note that the plugin is available only as a transformation step; it is not available as a Job plugin.
- Create a new Transformation. Select
File >
New >Transformation.
- In the
Design tab, select the
Alterian category, then select the
Json Decoder plugin and drag it to the transformation panel.
- In the
Design tab, select a source of JSON data.
- Configure the data grid tool with one field of type String on the
Meta tab, for example 'Message'.
- Populate the
Data tab with the JSON object strings you require. The JSON objects can be arbitrarily complex, and do not have to be the same as each other.
Note that the data grid can be replaced with any other step that generates a string field containing JSON, or that reads JSON from a file.
- Join the Data Grid to the
Json Decoder.
- Save the transformation.
- Open the
Json decoder and select the field that contains JSON from the
Field to decode drop-down menu.
- Select the
Fields tab and click the
Get Fields button. The inputs to this step will run and the data is parsed to the JSON decoder step.
- A results dialog shows the columns decoded from the JSON. If you have a large dataset or a continuous feed of JSON, you can limit the number of input rows scanned.
In this example, two columns of data have been detected called 'a' and 'b'. The JSON Decoder guesses the data types, but you can change them if the guess is incorrect. The
Required column allows you to discard certain decoded JSON objects if they do not fulfill your entered requirements. The default value is
Allowed. 
- If you do not want to decode a particular field, select the row and click delete.
- Add a text file output node to the transformation, connect it to the transformation and click the
Get Fields button. In the example shown below, the available fields are the original JSON (Message) plus any decoded fields (a and b).
- Select the fields you want to output and where you would like to save the file to.
- Save and run the transformation.
- The output file should contain the decoded values of all the JSON objects in the original Data Grid. In the example show below, the original JSON message is included for comparison.
Example
Your initial transformation should look like this:
|
|